package cn.tedu.tea.infrastructure.data.converter;

import cn.tedu.tea.dao.api.po.Content;
import cn.tedu.tea.domain.bo.ContentBO;
import cn.tedu.tea.protocol.param.ContentParam;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;

@Component
public class ContentConterver {
    public Content paramToPo(ContentParam contentParam) {
        Content content = new Content();
        BeanUtils.copyProperties(contentParam, content);
        Long nowTime = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        content.setGmtCreate(nowTime);
        content.setGmtModified(nowTime);
        return content;
    }

    public ContentBO poToBo(Content content) {
        ContentBO contentBO = new ContentBO();
        BeanUtils.copyProperties(content, contentBO);
        return contentBO;
    }

    public List<ContentBO> poListToBOList(List<Content> list) {
        List<ContentBO> contentBoList = new ArrayList<>();
        if (list != null && !list.isEmpty()) {
            for (Content content:list) {
                ContentBO contentBO = new ContentBO();
                BeanUtils.copyProperties(content,contentBO);
                contentBoList.add(contentBO);
            }
        }
        return contentBoList;
    }
}
